"""
整个JSON数据是一个对象
- 包含success、code、message、data字段，并且是必须存在的字段
- success字段为布尔类型
- code为整数
- message为以“登录成功”结尾的字符串
- data为对象，必须包含name、age字段
- data中的name字段必须等于lily
- data中的age必须是20
"""
import jsonschema

schema = {
    "type": "object",
    "properties": {
        "success": {"type": "boolean"},
        "code": {"type": "integer"},
        "message": {"pattern": "登录成功$"},
        "data": {
            "type": "object",
            "properties": {
                "name": {"const": "lily"},
                "age": {"const": 20}
            },
            "required": ["name", "age"]
        }
    },
    "required": ["success", "code", "message", "data"]
}

data = {
    "success": False,
    "code": 10000,
    "message": "xxx登录成功",
    "data": {
        "age": 20,
        "name": "lily"
    }
}
jsonschema.validate(instance=data,schema=schema)